import React, { useState, createContext, lazy } from "react";
import { HashRouter, Route, Switch } from "react-router-dom";
import { getAuthorization } from "./axios";
function isMobile() {
  let flag = navigator.userAgent.match(
    /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
  );
  return flag;
}
if (!isMobile() && window.location.hash != "#/oauth" && window.location.hash != "#/login-oauth") {
  alert("请使用手机登录！");
}
export const Context = createContext(null); // context 全局数据管理
console.log(window.location.pathname)
function App() {
  const [n, setN] = useState("zh");
  if (!getAuthorization() && window.location.hash != "#/login") {
    location.hash = "/login";
  }
  return (
    <HashRouter>
      <Context.Provider value={{ n, setN }}>
        <React.Suspense fallback={<div className="jiazai"></div>}>
          <Switch>
            <Route exact path="/" component={lazy(() => import("./Home"))} />
            <Route
              exact
              path="/login"
              component={lazy(() => import("./Login"))}
            />
            <Route
              exact
              path="/home"
              component={lazy(() => import("./Home"))}
            />
            <Route
              exact
              path="/my"
              component={lazy(() => import("./My"))}
            />
            <Route
              exact
              path="/load/:type"
              component={lazy(() => import("./LoadImg"))}
            />
            <Route
              exact
              path="/list/:type"
              component={lazy(() => import("./List"))}
            />
            <Route
              exact
              path="/sbada"
              component={lazy(() => import("./Sbada"))}
            />
             <Route
              exact
              path="/mini"
              component={lazy(() => import("./Mini"))}
            />
             <Route
              exact
              path="/light"
              component={lazy(() => import("./Light"))}
            />
          </Switch>
        </React.Suspense>
      </Context.Provider>
    </HashRouter>
  );
}

export default App;
